package com.qf.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qf.Excaption.MyExcaption;
import com.qf.domain.NewsDetail;

import com.qf.mapper.NewsCommentMapper;
import com.qf.mapper.NewsDetailMapper;
import com.qf.service.NewsCommentService;
import com.qf.service.NewsDetailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class NewsDetailServiceimpl implements NewsDetailService {
    @Autowired
    private NewsDetailMapper newsDetailMapper;
    @Autowired
    private NewsCommentMapper newsCommentMapper;
    @Override
    public List<NewsDetail> selectAll(Integer page, Integer size,String title) {
        PageHelper.startPage(page,size);
        List<NewsDetail> list=newsDetailMapper.selectAll(title);
        PageInfo<NewsDetail> pageInfo=new PageInfo<>(list);
        return list;
    }


    @Override
    @Transactional
    public int deletenews(Integer id) {
        if (id==null){
            throw new MyExcaption("数据无法接收",500);
        }
        int i=newsDetailMapper.deletenews(id);
        int c=newsCommentMapper.deletecomment(id);
        if (i==1){
            return 1;
        }else {
            throw new MyExcaption("数据无法接收",500);
        }


    }
}
